package com.tm.storage.contoller;

import com.tm.storage.entity.StorageEntity;
import com.tm.storage.service.StorageService;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping
public class StorageController {
    
    private final StorageService storageService;

    public StorageController(StorageService storageService) {
        this.storageService = storageService;
    }
    
    @PutMapping("updateStorage")
    public int updateStorage(@RequestBody Map<String,String> map){
        StorageEntity storage = new StorageEntity();
        storage.setId(Long.parseLong(map.get("id")));
        storage.setTotal(Integer.parseInt(map.get("total")));
        storage.setUsed(Integer.parseInt(map.get("used")));
        return storageService.updateStorage(storage);
    }
}
